package 算法;

import java.util.*;

/**
 * @Author: 朱胜伟
 * @CreateTime: 2020-12-04 08:26
 * @Description:
 */
public class _周赛 {
    public boolean isPossible(int[] nums) {
        Map<Integer,PriorityQueue<Integer>> map = new HashMap<>();
        for (int num : nums) {
            
            if(!map.containsKey(num)){
                map.put(num,new PriorityQueue<>());
            }
            if(map.containsKey(num-1)){
                int minr = map.get(num-1).poll();
                if(map.get(num-1).isEmpty()){
                    map.remove(num-1);
                }
                map.get(num).offer(minr+1);
            }else {
                map.get(num).offer(1);
            }
        }
        for (Map.Entry<Integer, PriorityQueue<Integer>> integerPriorityQueueEntry : map.entrySet()) {
            for (Integer integer : integerPriorityQueueEntry.getValue()) {
                if(integer < 3) return false;
            }
        }

        return true;
    }
    public int[] mostCompetitive(int[] nums, int k) {
        Deque<Integer> deque = new ArrayDeque<>();
        int len = nums.length;
        for (int i = 0; i < len; i++){
            int temp = nums[i];
            while (!deque.isEmpty() && k > 0 && deque.peekLast() > temp){
                deque.pollLast();
                k--;
            }
            deque.push(temp);
        }
        for (int i = 0; i < k; i++){
            deque.pollLast();
        }
        int[] res = new int[len-k];
        int j = 0;
        for (Integer integer : deque) {
            res[j++] = integer;
        }
        return res;
    }
}
